﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MaxLeaf.Platform.Commons;
using CommonsLib.Settings;

namespace MaxLeaf.Platform.Functions
{
    public class BaseFunc
    {
         

        

        public static string SpecialCharDeal(string strOrigin)
        {

            if (strOrigin == null) return "";
            if (strOrigin.IndexOf("'", 0) >= 0)
            {
                strOrigin = strOrigin.Replace("'", "''");
            }

            return strOrigin;
        }


        public static string FormatWithZero(string strField_Char, int intField_length)
        {

            string strForm_char = strField_Char.Trim();
            int iDiff = intField_length - strForm_char.Length;

            if (BaseFunc.IsNumeric(strForm_char))
            {
                for (int i = 0; i < iDiff; i++)
                {
                    strForm_char = "0" + strForm_char;
                }
            }
            return strForm_char.ToUpper();
        }

        public static bool IsNumeric(string Value)
        {
            return IsNumeric(Value, false);
        }

        public static bool IsNumeric(string Value, bool bIncludeSpecString)
        {
            if (bIncludeSpecString)
            {
                Value = Value.Replace("$", "").Replace("(", "").Replace(")", "").Trim();
            }

            string strValue = Value;

            int iLength = strValue.Split(new char[] { '.' }, StringSplitOptions.RemoveEmptyEntries).Length;

            if (strValue == null || strValue == string.Empty || iLength == 0 || iLength > 2)
            {
                return false;
            }
            else
            {
                strValue = strValue.Replace(",", "");

                if (strValue.Substring(0, 1) == "-")
                {
                    strValue = strValue.Substring(1, strValue.Length - 1);
                    if (strValue == "") return false;
                }

                foreach (char c in strValue.ToCharArray())
                {
                    if (!(char.IsNumber(c) || c == '.'))
                    {
                        return false;
                    }
                }

                if (strValue.IndexOf("..") > 0) return false;
                return true;
            }

        }

    }
}
